package com.example.controller;

import com.example.dto.*;
import com.example.service.*;
import com.example.util.Result;
import jakarta.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

/**
 * ClassName:SuperAdminController
 * Package:com.example.controller
 * User:HP
 * Date:2025/8/25
 * Time:下午8:35
 * Author 周东汉
 * Version 1.0
 * Description:
 */


@RestController
@RequestMapping("/api")
@PreAuthorize("hasRole('ROLE_SUPER_ADMIN')")
public class SuperAdminController {

    @Autowired
    LibraryService libraryService;

    @Autowired
    UserService userService;

    @Autowired
    RoomService roomService;

    @Autowired
    BookshelfService bookShelfService;

    @Autowired
    SeatService seatService;

    @PostMapping("/admin/add")
    public Result addAdmin(@RequestBody AdminAddDTO adminAddDTO) {
        return userService.addAdmin(adminAddDTO);
    }

    @DeleteMapping("/admin/delete")
    public Result deleteAdmin(@RequestParam("id") Long id) {
        return userService.deleteAdmin(id);
    }

    @GetMapping("/admins")
    public Result getAdmins() {
        return userService.getAdmins();
    }

    @PostMapping("/library/add")
    public Result addLibrary(@RequestBody LibraryAddDTO libraryAddDTO) {
        return libraryService.addLibrary(libraryAddDTO);
    }

    @PostMapping("room/add")
    public Result addRoom(@RequestBody RoomAddDTO roomAddDTO) {
        return roomService.addRoom(roomAddDTO);
    }

    @PostMapping("/room/update")
    public Result updateRoom(@RequestBody RoomUpdateDTO roomUpdateDTO) {
        return roomService.updateRoom(roomUpdateDTO);
    }

    @PostMapping("/bookshelf/add")
    public Result addBookShelf(@RequestBody @Valid BookShelfAddDTO bookShelfAddDTO) {
        return bookShelfService.addBookShelf(bookShelfAddDTO);
    }

    @PostMapping("/seat/add")
    public Result addSeat(@RequestBody @Valid SeatAddDTO seatAddDTO) {
        return seatService.addSeat(seatAddDTO);
    }

    @PreAuthorize("hasAnyRole('ROLE_SUPER_ADMIN','ROLE_ADMIN')")
    @PostMapping("/password/reset")
    public Result resetPassword(@RequestParam Long userId) {
        return userService.resetPassword(userId);
    }

    @PreAuthorize("hasRole('ROLE_SUPER_ADMIN')")
    @PostMapping("/admin/status")
    public Result changeAdminStatus(@RequestParam Long userId, @RequestParam Integer status) {
        return userService.changeAdminStatus(userId, status);
    }



}
